using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class RoleObjectRepository : 
    IRoleObjectRepository 
  {
    public IBusinessObjectCollection<IRole> RetrieveAll()
    {
      var query = new RoleLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<IRole> Retrieve(RoleLoadSettings query)
    {
      query = RoleLoadSettings.FromRoleLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaRoleInfoCollection.GetRoleInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaRoleEditCollection.GetRoleEditCollection(query);
        return result;
      }
    }

    public IRole RetrieveOne(RoleLoadSettings query)
    {
      query = RoleLoadSettings.FromRoleLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaRoleInfoCollection.GetRoleInfoCollection(query);
        return result.FirstOrDefault<IRole>();
      }
      else
      {
        var result = CslaRoleEditCollection.GetRoleEditCollection(query);
        return result.FirstOrDefault<IRole>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(RoleLoadSettings query)
    {
      query = RoleLoadSettings.FromRoleLoadSettings(query);
      return CslaRoleInfoCollection.GetCount(query);
    }

    public IRole New()
    {
      return CslaRoleEdit.New();
    }

    public void Save(IBusinessObjectCollection<IRole> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(IRole obj)
    {
      throw new NotImplementedException();
    }
  }
}
